<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<?php
// webboard administrator page
//
// digiboard by digitalboom.org
// http://www.digitalboom.org
//
// Information Technology program
// Sirindhorn International Institute of Technology
// Thammasat University, Rangsit Campus
// http://www.siit.tu.ac.th
//
// first created on: 2001 Dec xx  by Park it://5
// last modified on: 2003 Aug 21 by bact'
//
//sticky topic functions by hoho

include("settings/config.inc.php");
include("settings/accounts.inc.php");
include("settings/forum.inc.php");

extract($_POST);
extract($_GET);
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$DGB["ENCODING"];?>">
<title><?=$DGB["WEBBOARD_NAME"];?> / admin</title>
<meta http-equiv="Pragma" content="no-cache">
<link rel="stylesheet" href="<?=$DGB["STYLESHEET"];?>" type="text/css">
</head>

<?php
if (isset($deletetopic) || isset($movetopic) || isset($addstickytopic) || isset($deletestickytopic) || isset($markxtopic) || isset($unmarkxtopic)) {
 // start process
 @mysql_connect ($DGB["DB_SERVER"], $DGB["DB_USER"], $DGB["DB_PASS"]);
 @mysql_select_db($DGB["DB_DBNAME"]);

 // check Admin Username and Password
 if ($auth_user == $DGB["ADMIN_USERNAME"] &&
     $auth_pass == $DGB["ADMIN_PASSWORD"]) {

  // check function
  if (isset($deletetopic)) {
   if (empty($DeleteTopic_ID)) {
    $javatext = "<script language='JavaScript'>alert('Please provide Topic ID to delete!'); history.back();</script>";
    echo $javatext;
    exit;
   } else { 
    $query = "DELETE FROM ".$DGB['DB_TOPICS_TABLE']. " WHERE Topic_ID=$DeleteTopic_ID";
    @mysql_query($query) or die(mysql_error());
    $query = "DELETE FROM ".$DGB['DB_ANSWERS_TABLE']. " WHERE Topic_ID=$DeleteTopic_ID";
    @mysql_query($query) or die(mysql_error());
    $javatext = "<script language='JavaScript'>alert('Topic ID : $DeleteTopic_ID has been deleted successfully.'); history.back();</script>";
    echo $javatext;
    exit;
   }
  }
 elseif(isset($movetopic)) {
   if (empty($MoveTopic_ID)) {
    $javatext = "<script language='JavaScript'>alert('Please provide Topic ID to move!'); history.back();</script>";
    echo $javatext;
    exit;
   } elseif($MoveToForum <= 0) {
    $javatext = "<script language='JavaScript'>alert('Please select Forum to move topic to!'); history.back();</script>";
    echo $javatext;
    exit;
   } else { 
   $query = "UPDATE ".$DGB['DB_TOPICS_TABLE']." SET Forum_ID=$MoveToForum WHERE Topic_ID=$MoveTopic_ID";
    @mysql_query($query) or die(mysql_error());
    $javatext = "<script language='JavaScript'>alert('Topic ID : $MoveTopic_ID has been moved to ".$DGB_FORUM_NAME[$MoveToForum]." successfully.'); history.back();</script>";
    echo $javatext;
    exit;
   }  
  }
  elseif(isset($markxtopic)) {
   if (empty($ExplicitTopic_ID)) {
    $javatext = "<script language='JavaScript'>alert('Please provide Topic ID to mark as Explicit Content!'); history.back();</script>";
    echo $javatext;
    exit;
   } else {
   $query = "UPDATE ".$DGB['DB_TOPICS_TABLE']." SET  ExplicitContent=1 WHERE Topic_ID=$ExplicitTopic_ID";
    @mysql_query($query) or die(mysql_error());
    $javatext = "<script language='JavaScript'>alert('Topic ID : $ExplicitTopic_ID has been marked as Explicit Content successfully.'); history.back();</script>";
    echo $javatext;
    exit;
   }  
  }
  elseif(isset($unmarkxtopic)) {
   if (empty($ExplicitTopic_ID)) {
    $javatext = "<script language='JavaScript'>alert('Please provide Topic ID to unmark from Explicit Content!'); history.back();</script>";
    echo $javatext;
    exit;
   } else {
   $query = "UPDATE ".$DGB['DB_TOPICS_TABLE']." SET ExplicitContent=0 WHERE Topic_ID=$ExplicitTopic_ID";
    @mysql_query($query) or die(mysql_error());
    $javatext = "<script language='JavaScript'>alert('Topic ID : $ExplicitTopic_ID has been unmarked from Explicit Content successfully.'); history.back();</script>";
    echo $javatext;
    exit;
   }  
  }
  elseif (isset($addstickytopic)) {
   if (empty($AddStickyTopic_ID)) {
    $javatext = "<script language='JavaScript'>alert('Please provide Topic ID to add to Sticky list!'); history.back();</script>";
    echo $javatext;
    exit;
   } else {
    // open Sticky Topics list file.
    $filename = "settings/stickytopics.txt";
    $fp=fopen("$filename","a+");
    trim($AddStickyTopic_ID);
    fputs($fp,"$AddStickyTopic_ID\n");
    fclose($fp);
   }
  }
 elseif (isset($deletestickytopic)) {
   if (empty($DeleteStickyTopic_ID)) {
    $javatext = "<script language='JavaScript'>alert('Please provide Topic ID to delete from Sticky list!'); history.back();</script>";
    echo $javatext;
    exit;
   } else {
    // open Sticky Topics list file.
    $filename = "settings/stickytopics.txt";
    $line = file($filename);
 
    for ($i=0; $i<sizeof($line); $i++) {
     // delete DeleteStickyTopicID in array
     // change old TopicID to 0
     // delete and Recreate file

     // convert string into integer
     $DeleteStickyTopic_ID += 0;
 
     if ($line[$i]==$DeleteStickyTopic_ID) {
      $line[$i]=0;
     }
    }
  
    unlink("settings/stickytopics.txt"); // delete file

    $fp = fopen("$filename","w");
    for ($i=0; $i<sizeof($line); $i++) 	{
     // write file
     if ($line[$i]==0) {
     // do nothing
     } else {
      fputs($fp,"$line[$i]");
     }
    }
    fclose($fp);
    }
   }
  } else {
   $javatext = "<script language='JavaScript'>alert('Invalid username or password'); history.back();</script>";
   echo $javatext;
   exit;
  }
  }
?>

<body bgcolor="#ffffee">
<table class="pHead" width="100%" border=0 cellspacing=0 cellpadding=0>
  <tr valign="middle">
    <td align="center"><b><font color="#F8F8F8"><?=$DGB["WEBBOARD_NAME"];?></font> / admin</b></td>
  </tr>
</table>
<table class="pSubHead" width="100%" border=0 cellspacing=0 cellpadding=0>
 <tr>
  <td align="center" valign="middle">
  <?=$DGB["NAME"];?> <?=$DGB["VERSION"];?>
   </td>
</tr>
</table>

<!-- <form name="form1" method="post" action="admin.php"> -->
<form name="form1">
 <table width="60%" border=0 cellspacing=0 cellpadding=0 align="center">
 <tr align="center">
 <td>Please enter admin username, password and then click preferred function button<br><br></td>
 </tr> 
 </tr>
  <tr align="center"> 
   <td>
   <label accesskey=U>Username :  <input type="text" name="auth_user" size=20 maxlength=25></label><br>
   <label accesskey=P>Password : <input type="password" name="auth_pass" size=20 maxlength=25></label></td>
  </tr>
 </table>
 <br>
 
 <!--MOVE TOPIC-->
 <table border=0 cellspacing=0 cellpadding=1 align="center">
  <tr> 
   <td class="mbMouseOver">Move Topic
   <table width="100%" border=0 cellspacing=4 cellpadding=0 align="center" bgcolor="#ffffee">
   <tr>
   <td>
    <label><input type="text" name="MoveTopic_ID" size=10 maxlength=10> to
    <select name="MoveToForum">
    <option value=0>(forum)</option>
    <? for ($i = 1; $i <= $DGB_FORUM['NUMBER']; $i++) {
           echo "<option value=\"$i\">".$DGB_FORUM_NAME[$i]."</option>\n"; }?>
    </select></label>
		<input type="submit" name="movetopic" value='move'>
    </td>
    </tr>
    </table>
  </td>
 </tr>
</table>
<br>

<!--ADD/DELETE STICKY TOPIC-->
<table border=0 cellspacing=0 cellpadding=1 align="center">
<tr>
<td class="mbMouseOver">Sticky Topics
<table width="100%" border=0 cellspacing=4 cellpadding=0 align="center" bgcolor="#ffffee">
 <tr>
  <td>
   <label accesskey=A><input type="text" name="AddStickyTopic_ID" size=10 maxlength=10></label>
   <input type="submit" name="addstickytopic" value="add new"><br>
    <?php
     // open sticky topics list file.
     $filename = "settings/stickytopics.txt";
     if (file_exists($filename)) {
      $fp = fopen("$filename","r");
      while ($x=fgets($fp,99)) {
       echo "<label><input type=\"radio\" name=\"DeleteStickyTopic_ID\" value=\"$x\">$x</label><br>";
      }
      fclose($fp);
     } else {
      echo "(File Not Found)";
     }
    ?>
      <input type="submit" name="deletestickytopic" value="remove selected">
   </td>
  </tr>
 </table>
</td>
</tr>
</table>
<br>

 <!--MARK/UNMARK TOPIC EXPLICIT CONTENT-->
 <table border=0 cellspacing=0 cellpadding=1 align="center">
  <tr> 
   <td class="mbMouseOver">"Explicit Content" Topic
   <table width="100%" border=0 cellspacing=4 cellpadding=0 align="center" bgcolor="#ffffee">
   <tr>
   <td>
    <label><input type="text" name="ExplicitTopic_ID" size=10 maxlength=10></label>
		<input type="submit" name="markxtopic" value='mark'>
    <input type="submit" name="unmarkxtopic" value='unmark'></td>
    </tr>
    </table>    
    </td>
  </tr>
 </table>
<br>

 <!--DELETE TOPIC-->
 <table border=0 cellspacing=0 cellpadding=1 align="center">
  <tr> 
   <td class="mbMouseOver">Delete Topic (from Database)
   <table width="100%" border=0 cellspacing=4 cellpadding=0 align="center" bgcolor="#ffcccc">
   <tr>
   <td>
    <label><input type="text" name="DeleteTopic_ID" size=10 maxlength=10></label>
		<input type="submit" name="deletetopic" value='delete'></td>
    </tr>
    </table>    
    </td>
  </tr>
 </table>
  
</form>

<?php
 include("html/footer.html");
?>
</body>
</html>





